Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

acceptance: Refactors java acceptance tests #10659

Closed

Conversation

rohangulati
Copy link

@rohangulati rohangulati commented Nov 12, 2016

Fixes #4591

This moves the java acceptance test to separate java files inside acceptance/java package to ease editing. Positive java test cases live under acceptance/java/success and negative test cases under acceptance/java/fail. The go test code invokes a bash scripts run_java_test.sh which compiles and runs TestRunner.java inside the test docker container. TestRunner.java is responsible for running all java test under acceptance/java/success and acceptance/java/fail. It does so by accepting 2 command line arguments [expectedOutcome] [test_dir]. TestRunner also makes sure that all generated files (.class and .pk8) files are cleaned up.

This change is Reviewable

@CLAassistant
Copy link

CLAassistant commented Nov 12, 2016

CLA assistant check
All committers have signed the CLA.

@rohangulati rohangulati force-pushed the java-acceptance-refactor branch 4 times, most recently from 9ad1058 to b897fb6 Compare November 12, 2016 17:53
@rohangulati rohangulati changed the title Refactors java acceptance tests acceptance: Refactors java acceptance tests Nov 12, 2016
@tamird
Copy link
Contributor

tamird commented Nov 12, 2016

CI failure looks related to some issues on master (should go away with a rebase).

@tamird
Copy link
Contributor

tamird commented Nov 12, 2016

While you're rebasing, please include the entire PR description in your commit message.

Fixes cockroachdb#4591

This moves the java acceptance test to separate java files inside `acceptance/java` package to ease editing. Positive java test cases live under `acceptance/java/success` and negative test cases under `acceptance/java/fail`. The go test code invokes a bash scripts 'run_java_test.sh' which compiles and runs 'TestRunner.java` inside the test docker container. 'TestRunner.java` is responsible for running all java test under 'acceptance/java/success` and 'acceptance/java/fail'. It does so by accepting 2 command line arguments [expectedOutcome] [test_dir]. 'TestRunner' also makes sure that all generated files (.class and .pk8) files are cleaned up.
@rohangulati
Copy link
Author

rohangulati commented Nov 13, 2016

@tamird Rebased with master and included the description in the commit message

@knz
Copy link
Contributor

knz commented Nov 14, 2016

Thanks for your help. Some minor comments left.


Reviewed 3 of 6 files at r1.
Review status: 3 of 6 files reviewed at latest revision, 8 unresolved discussions, all commit checks successful.


pkg/acceptance/java/TestRunner.java, line 31 at r1 (raw file):

    public static void main(String[] args) throws Exception {
        if (args.length < 2) {
            throw new Exception("unexpected : missing arguments. usage : java TestRunner [SUCCESS/FAIL] [dir]");

In English there is no space between a colon (:) and the previous word. e.g. "unexpected: missing ..." (also see below)
Put "usage: ..." on a different line; e.g. "unexpected: missing arguments\nusage: java ..."


pkg/acceptance/java/TestRunner.java, line 37 at r1 (raw file):

        ExpectedOutcome expectedOutcome = ExpectedOutcome.parse(mode);
        if (expectedOutcome == null) {
            throw new Exception("unexpected : missing arguments. usage : java TestRunner [SUCCESS/FAIL] [dir]");

The null value doesn't say the argument was missing, but rather that it wasn't correct. Make the exception more informative.


pkg/acceptance/java/TestRunner.java, line 88 at r1 (raw file):

        for (File file : files) {
            if (!file.getName().contains(".java")) {

Simplify: if (file.getName().contains(".hava")) { javaFiles.add(file); }

also, use endsWith not contains.


pkg/acceptance/java/TestRunner.java, line 179 at r1 (raw file):

        }
    }
}

Missing newline at end of file.


pkg/acceptance/java/fail/JavaFailureTest.java, line 46 at r1 (raw file):

            throw new Exception("unexpected: DROP TABLE reports " + res + " rows changed, expecting 0");
        }
        stmt = conn.prepareStatement("SELECT 1, 2 > ?, ?::int, ?::string, ?::string, ?::string, ?::string, ?::string");

Move this test into a separate file.


pkg/acceptance/java/fail/JavaFailureTest.java, line 67 at r1 (raw file):

            throw new Exception("unexpected");
        }
        stmt = conn.prepareStatement("CREATE TABLE accounts (id INT PRIMARY KEY, balance INT, cdate DATE)");

Move this test (this CREATE together with the INSERT below) into a separate file.


pkg/acceptance/java/success/JavaSuccessTest.java, line 48 at r1 (raw file):

            throw new Exception("unexpected: DROP TABLE reports " + res + " rows changed, expecting 0");
        }
        stmt = conn.prepareStatement("SELECT 1, 2 > ?, ?::int, ?::string, ?::string, ?::string, ?::string, ?::string");

Split test here (see comment above)


pkg/acceptance/java/success/JavaSuccessTest.java, line 69 at r1 (raw file):

            throw new Exception("unexpected");
        }
        stmt = conn.prepareStatement("CREATE TABLE accounts (id INT PRIMARY KEY, balance INT, cdate DATE)");

Split test here (see comment above)


Comments from Reviewable

@tamird
Copy link
Contributor

tamird commented Nov 14, 2016

Reviewed 4 of 6 files at r1.
Review status: 4 of 6 files reviewed at latest revision, 14 unresolved discussions, all commit checks successful.


pkg/acceptance/java/run_cleanup.sh, line 4 at r1 (raw file):

# cleans all {.class, .pk8} files in the current directory
find . -type f -name "*.class" -exec rm -f {} \;
find . -type f -name '*.class' -or -name '*.pk8' -exec rm -f {} \;

pkg/acceptance/java/run_java_test.sh, line 2 at r1 (raw file):

#!/usr/bin/env bash
set -e

set -euo pipefail


pkg/acceptance/java/run_java_test.sh, line 9 at r1 (raw file):

export CLASSPATH=$CLASSPATH:$JAVA_ROOT/success:$JAVA_ROOT/fail:$JAVA_ROOT

cd $JAVA_ROOT

how come this is necessary?


pkg/acceptance/java/TestRunner.java, line 9 at r1 (raw file):

/*
This class compiles and runs all java files under a directory.

perhaps i'm missing something, but why is this test runner written in java? it seems to me that this thing amounts to little more than shelling out to various tools, and that there is little or no benefit to it being written in java.

given that java is not a core competency for us, I would prefer to see this written in Go.


pkg/acceptance/java/TestRunner.java, line 59 at r1 (raw file):

                        break;
                    }
                    // This test should have "PASSED" but "FAILED

broken sentence.


pkg/acceptance/java/fail/JavaFailureTest.java, line 7 at r1 (raw file):

    public static void main(String[] args) throws Exception {
        Class.forName("org.postgresql.Driver");
        String DB_URL = "jdbc:postgresql://";

this connection string construction code is duplicated; can it be shared?


Comments from Reviewable

@rohangulati
Copy link
Author

Review status: 4 of 6 files reviewed at latest revision, 14 unresolved discussions, all commit checks successful.


pkg/acceptance/java/TestRunner.java, line 9 at r1 (raw file):

Not specific reason. It was as per the suggestion "the different Java tests should be executed one after another by test logic written in Java" mention in the issue(#4578) description. I agree that this should be written in go. I will rewrite this in go.


Comments from Reviewable

@spencerkimball
Copy link
Member

@knz, @dt, @mjibson what remains to be done here?

@dt
Copy link
Member

dt commented Mar 29, 2017

At the very least we need to rebase it, in particular to pick up 66c28b5.

Beyond that, looks like there's @tamird's objection to the loop that runs the individual tests being on the java side rather than in Go, but that potentially could get changed later if/when it becomes a pain point.

@spencerkimball
Copy link
Member

@dt could we get this merged, assuming it's straightforward? And update / close #4591.

@justinj
Copy link
Contributor

justinj commented Nov 1, 2017

I'm going to close this since it appears to have died and #4591 was closed by #19321.

@justinj justinj closed this Nov 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants